/**
 * author:Administrator
 * date:2016/2/24
 * desc:TODO
 */

'use strict';

let seq = 1;
let list = {};


class CategoryRepoImpl {

  static * genId() {
    return 'coupon_' + (seq++);
  }

  static * find(id) {
    return list[id];
  }

  static * store(coupon) {
    if (!coupon.id) coupon.id = yield CategoryRepoImpl.genId();
    list[coupon.id] = coupon;
  }

  static * decrease(id, count, t) {
    let item = list[id];
    if (item.remain >= count) {
      item.remain -= count;
      return true;
    }
    return false;
  }
}
module.exports = CategoryRepoImpl;